/***************************************************************
 * Name:      SetupCreatorMain.h
 * Purpose:   Defines Application Frame
 * Author:    Jeremie Fouche (jeremie.fouche@gmail.com)
 * Created:   2007-05-05
 * Copyright: Jeremie Fouche ()
 * License:
 **************************************************************/

#ifndef SC_CREATORFRAME_H_INCLUDED
#define SC_CREATORFRAME_H_INCLUDED

#include <wx/validate.h>

#include "creatorapp.h"
#include "creatorgui.h"

#include "sc/context.h"


/**
* @class CreatorPanel
*/
class CreatorPanel : public CreatorPanelGui
{
public:
    CreatorPanel(wxWindow* parent, sc::SetupContext* pContext);

protected:
    /**
    * @class ElementTID
    *
    * Represent the tree item data
    */
    class ElementTID : public wxTreeItemData
    {
    public:
        sc::cfg::Element*   m_pElement;
        sc::cfg::Attribute* m_pAttribute;
        enum Type { ELEMENT, ATTRIBUTE } m_type;

        ElementTID(sc::cfg::Element* pElement, sc::cfg::Attribute* pAttribute = NULL)
        : m_pElement(pElement), m_pAttribute(pAttribute)
        {
            m_type = pAttribute ? ATTRIBUTE : ELEMENT;
        }
    };

    /// Attributes
    sc::SetupContext* m_pContext;

public:
    wxTreeItemId AddTreeChild(const wxTreeItemId& hParent, const sc::cfg::Element& rcElement);

protected:
    sc::cfg::Element* GetElement(const wxTreeItemId& tid) const;
    sc::cfg::Attribute* GetAttribute(const wxTreeItemId& tid) const;
    void SetAttribute(const sc::cfg::Attribute& rcAttribute) const;
    void SetElement(const sc::cfg::Element& rcElement) const;

    /// Virtual event handlers, from wxFB CreatorPanelGui class
    virtual void OnTreeCreatorSelChanged( wxTreeEvent& event );
    virtual void OnTreeCreatorSelChanging( wxTreeEvent& event );
};

/**
* @class CreatorFrame
*/
class CreatorFrame : public CreatorFrameGui
{
public:
    CreatorFrame(wxWindow* parent);

protected:
    /// Attributes
    sc::Context   m_context;

public:
    int LoadContext(const wxString& sFilename);

protected:
    void Load(void);
    CreatorPanel* AddPage(const wxString& sName);

    /// Virtual event handlers, from wxFB CreatorFrameGui class
    virtual void OnFileOpen( wxCommandEvent& event );
    virtual void OnFileSave( wxCommandEvent& event );
    virtual void OnFileSaveAs( wxCommandEvent& event );
    virtual void OnFileExit( wxCommandEvent& event );
    virtual void OnHelpAbout( wxCommandEvent& event ){ event.Skip(); }

private:
    DECLARE_EVENT_TABLE()
};

#endif // SC_CREATORFRAME_H_INCLUDED
